package com.lanou.activity.Service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.activity.Service.SaleCdnService;
import com.lanou.activity.mapper.SaleCdnMapper;
import com.lanou.activity.utils.Constant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class SaleCdnServiceImpl implements SaleCdnService{

    @Resource
    private SaleCdnMapper saleCdnMapper;


    /**
     * @description 查询供应商的名称supName 和供应商公司名supComp
     * @author Lonely
     * @date 17/9/23
     * @return
     * @param
     */
    @Override
    public List<Map<String, Object>> findSupplier() {
        return saleCdnMapper.findSupplier();
    }

    /**
     * @description 添加促销条件信息
     * @author Lonely
     * @date 17/9/23
     * @return
     * @param
     */
    @Override
    public int addSaleCdnInfo(Map<String, Object> params) {
        return saleCdnMapper.insertSaleCdnInfo(params);
    }

    @Override
    public PageInfo<Map<String, Object>> findSaleCdnList(Map<String, Object> params) {
        Integer currentPage = params.get("currentPage") == null ? 1 : Integer.parseInt((String) params.get("currentPage"));
        Integer pageSize = 0;
        try {
            pageSize   = params.get("pageSize") == null ? Constant.CURRENTPAGE : Integer.parseInt((String) params.get("pageSize"));
        }catch (Exception e){
            pageSize=Constant.CURRENTPAGE;
        }
        System.out.println(currentPage+"------"+pageSize);
        PageHelper.startPage(currentPage, pageSize);
        List<Map<String, Object>> list = saleCdnMapper.findSaleCdnList(params);
        return new PageInfo<Map<String, Object>>(list);
    }

    @Override
    public int updateSaleCdn(Map<String, Object> params) {
        return saleCdnMapper.updateSaleCdn(params);
    }
}
